# 定义一些公用的工具
from flask import current_app
from flask import g
from flask import session
import functools
from info.models import User


def index_class(item):
    if item == 1:
        return 'first'
    if item == 2:
        return 'second'
    if item == 3:
        return 'third'
    return


def user_status_monitoring(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        user_id = session.get('user_id', None)
        # 2.是的话就取出用户的信息
        user = None
        if user_id:
            try:
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        g.user = user

        return f(*args, **kwargs)

    return wrapper
